'use strict'
const whiteList = require('../lib/whiteList')
const tagService= require('../services').tagService
const tagController = {}

// 获取所有分类
tagController.getTopTag = async (ctx, next) => {
    const result = await tagService.getTopTags()
    ctx.result = result
    return next()
}

// 创建分类
tagController.createTag = async (ctx, next) => {
    whiteList.needAdmin(ctx, next)
    const tagList = ctx.request.body
    const result = await tagService.createTag(tagList)
    console.log(result);
    ctx.result = result
    return next()
}

// 删除分类
tagController.deleteTag = async (ctx, next) => {
    whiteList.needAdmin(ctx, next)
    const tagList = ctx.request.body
    const result = await tagService.deleteTag(tagList)
    ctx.result = result
    console.log(result)
    return next()
}

// 编辑一个分类
tagController.updateOneTag = async (ctx, next) => {
    whiteList.needAdmin(ctx, next)
    const category = ctx.request.body
    const result = await tagService.updateOneTag(category._id, category)
    ctx.result = result
    console.log(result)
    return next()
}

module.exports = tagController
